# 环形图
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.globals import ThemeType
df = pd.read_excel('某店铺促销方式分析.xlsx')
pie = Pie(init_opts=opts.InitOpts(width='1050px',height='400px',
                                 theme=ThemeType.LIGHT,page_title='环形图'))
pie.add(series_name='',
        data_pair=df[['促销方式','男']].values.tolist(),
        radius=120,center=['25%','55%'], # 饼图
        label_opts=opts.LabelOpts(formatter='{b}({d}%)'))
pie.add(series_name='',
        data_pair=df[['促销方式','女']].values.tolist(),
        radius=[80,120],center=['70%','55%'], # 环形图
        label_opts=opts.LabelOpts(formatter='{b}({d}%)'))
pie.set_global_opts(
        title_opts=opts.TitleOpts(
                title='男性和女性在某店铺不同促销方式下购买人数占比环形图'
                '(男性:左图,女性:右图)',
                pos_left='center'),
        legend_opts=opts.LegendOpts(is_show=False)
)
pie.render('例6-2.html')